<?php
namespace app\home\controller;
use think\Controller;
use think\Db;
use think\Input;

class Index extends Common
{
    public function index()
    {
        $articleList = Db::name('article ar')->join('category ca', 'ar.categoryid=ca.id', 'LEFT')->where('ar.status', 1)->field('ar.*,ca.name as catname')->limit(12)->select();
        // $category = array_unique(array_column($articleList, 'catname'));
        $category = [];
        foreach ($articleList as $key => $value) {
            $catname = $value['catname'];
            if ($catname && !in_array($catname, $category)) {
                $category[] = $catname;
            }
        }
        $this->assign([
            'articleList' => $articleList,
            'category'    => $category,
            'categoryAll' => implode(' ', $category).' -'
        ]);
        return $this->fetch();
    }

    public function test()
    {
        echo 1111;exit;
        return $this->fetch();
    }
}